package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.PortAgreementAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Classname PortAgreementAttrLinkHandler
 * @Description 接入电路类型=数字电路 且 接口类型（CE端信息）=G.703(75Ω)/G.703(120Ω)/V.35，端口封装协议=显示+必填，默认值 HDLC
 * @Author zhang.song
 * @Date 2021-03-10 20:50
 */
@Service
@AttrHandler(PortAgreementAttrHandler.class)
public class PortAgreementAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Autowired
    OperateInstAttrService operateInstAttrService;
    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        // 接入电路类型（CE端信息）
        KiteAttr attr1 = inst.getAttr("2_0000053");
        // 端口封装协议
        KiteAttr attr3 = inst.getAttr("200001724");
        if(KiteStringUtils.equals("1_0000229", attr1.getValue())) {
            // 接入电路类型（CE端信息）=数字电路
            KiteAttr attr2 = inst.getAttr("2_0000054");
            if(KiteStringUtils.equalsAny(attr2.getValue(), "1_0000142", "1_0000143", "1_0000146")) {

                // 接口类型（CE端信息）=G.703(75Ω)/G.703(120Ω)/V.35
                attr3.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
                attr3.setIsNull("F");
                operateInstAttrService.setAttrValue(inst, "200001724", attr3.getValue(), data.getSceneInstId(), "");
                return;
            }
        }

        attr3.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
        attr3.setIsNull("T");
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
